[Swoole] 在Ubuntu下安装、快速开始

您所在的位置:网站首页 win10 php74运行失败 [Swoole] 在Ubuntu下安装、快速开始

[Swoole] 在Ubuntu下安装、快速开始

2024-07-11 02:23| 来源: 网络整理| 查看: 265

本文主要讲述在 Ubuntu 下编译安装 Swoole,并根据官方文档给出的demo进行了测试和搬运,包括:TCP服务器、UDP服务器、HTTP服务器、WebSocket服务器、异步客户端、定时器和协程相关,通过模仿官方例子领略Swoole给PHPer带来全新的编程模式和思想。

它弥补PHP在网络编程的不足。

一、说明

运行环境:win10 下的 Ubuntu、PHP7.2、Swoole4.3

参考文档: https://wiki.swoole.com/wiki/page/p-quickstart.html

二、安装Swoole 下载解压 sudo wget https://github.com/swoole/swoole-src/archive/v4.3.6.tar.gz cp v4.3.6.tar.gz swoole-v4.3.6.tar.gz tar -zxvf swoole-v4.3.6.tar.gz cd swoole-v4.3.6 安装依赖 # 根据下面的编译提示进行选择安装 sudo apt-get install php-dev sudo apt-get install autoconf 编译安装 # 根据自己 php 安装的目录 cd swoole-v4.3.6 /usr/local/php/bin/phpize ./configure make sudo make install

make 的结果:

... ---------------------------------------------------------------------- Libraries have been installed in: /home/fly/swoole-src-4.3.6/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the `LD_RUN_PATH' environment variable during linking - use the `-Wl,--rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- Build complete. Don't forget to run 'make test'.

sudo make install 的结果:

Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/ Installing header files: /usr/local/php/include/php/ 配置 php.ini # 编译安装成功后,在 php.ini 文件加入 extension=swoole.so # extension=/usr/lib/php/20170718/swoole.so

查看是否加载 swoole 扩展

php -m 错误排查(可忽略)

下面错误很明显,需要指定 php-conf 路径:

configure: error: Cannot find php-config. Please use --with-php-config=PATH

解决方法:

./configure --with-php-config=/usr/local/php/bin/php-config

三、快速入门 a) TCP 服务器 # 创建 php 文件 vi tcp_server.php


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3